<?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use app\services\ProfitSettingService;

class ProfitSettingController extends AuthController
{
    public $currentHeader = 'header-operation';
    public $currentNav = 'profit-setting-nav';
    public $pageTitle = '';

    public function init() {
        parent::init();
        $this->service = new ProfitSettingService();
    }

    public function actionProfitSettingList() {
        $this->pageTitle = $this->t('profit', 'Profit Ratio List');
        return $this->show();
    }

    public function actionNewProfitSetting() {
        $this->pageTitle = $this->t('profit', 'Add New Profit Ratio Setting');
        return $this->show();
    }

    public function actionGetSolutionList() {
        $solutions = $this->service->getSolutionList();
        $this->jsonReturn(['data' => $solutions]);
    }

    public function actionNewProfitSettingHandle() {
        $solutionId = $this->I('id');
        $margin = $this->I('newValue');
        $this->service->updateSolutionMargin($solutionId, $margin);
        $this->OK($this->t('profit', 'Profit Ratio Set!'));
    }
}// end
